﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using ThePingMasterConfiguration.ViewModels;

namespace ThePingMasterConfiguration.Commands
{
    public class RemoveAddressCommand : ICommand
    {
        private readonly ConfigurationModel _model;

        public RemoveAddressCommand(ConfigurationModel model)
        {
            _model = model;
        }

        public void Execute(object parameter)
        {
            _model.Addresses.Remove(_model.SelectedAddress);
        }

        public bool CanExecute(object parameter)
        {
            return _model.SelectedAddress != null;
        }

        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }
    }
}
